<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Redis数据结构与内存管理 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .type-tag {
            display: inline-block;
            padding: 0.25rem 0.75rem;
            border-radius: 9999px;
            font-size: 0.75rem;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }
        .section-divider {
            position: relative;
            height: 80px;
            overflow: hidden;
        }
        .section-divider svg {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
        }
        .data-structure-diagram {
            background-color: #f8fafc;
            border-radius: 0.5rem;
            padding: 1.5rem;
        }
        .code-block {
            font-family: 'Courier New', Courier, monospace;
            background-color: #f3f4f6;
            padding: 1rem;
            border-radius: 0.375rem;
            overflow-x: auto;
        }
        .floating-icon {
            position: absolute;
            opacity: 0.1;
            z-index: 0;
        }
        .floating-icon-1 {
            top: 20%;
            left: 5%;
        }
        .floating-icon-2 {
            top: 60%;
            right: 5%;
        }
        .floating-icon-3 {
            bottom: 10%;
            left: 15%;
        }
        .content-wrapper {
            position: relative;
            z-index: 1;
        }
        .nav-link {
            position: relative;
        }
        .nav-link::after {
            content: '';
            position: absolute;
            bottom: -2px;
            left: 0;
            width: 0;
            height: 2px;
            background-color: #667eea;
            transition: width 0.3s ease;
        }
        .nav-link:hover::after {
            width: 100%;
        }
        .active-nav {
            color: #667eea;
            font-weight: 500;
        }
        .active-nav::after {
            width: 100%;
        }
        .drop-cap::first-letter {
            float: left;
            font-size: 4rem;
            line-height: 0.8;
            margin-right: 0.5rem;
            margin-top: 0.25rem;
            color: #667eea;
            font-weight: 700;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 relative overflow-hidden">
        <div class="floating-icon floating-icon-1">
            <i class="fas fa-database text-6xl"></i>
        </div>
        <div class="floating-icon floating-icon-2">
            <i class="fas fa-memory text-8xl"></i>
        </div>
        <div class="floating-icon floating-icon-3">
            <i class="fas fa-server text-7xl"></i>
        </div>
        
        <div class="container mx-auto px-6 relative z-10">
            <div class="flex flex-col md:flex-row items-center">
                <div class="w-full md:w-2/3">
                    <h1 class="text-4xl md:text-5xl font-bold mb-4 leading-tight">Redis数据结构与内存管理</h1>
                    <p class="text-xl md:text-2xl mb-8 opacity-90">探索Redis高性能背后的核心机制</p>
                    <div class="bg-white bg-opacity-20 backdrop-filter backdrop-blur-sm rounded-lg p-6 max-w-2xl">
                        <p class="drop-cap">Redis不仅仅是一个简单的键值存储，它提供了多种数据类型，每种数据结构都有其独特的应用场景，并且都经过精心设计，以最大化利用内存的效率，提升性能。掌握Redis的内存管理机制，是构建高性能应用的关键。</p>
                    </div>
                </div>
                <div class="w-full md:w-1/3 mt-10 md:mt-0 flex justify-center">
                    <img src="https://cdn.nlark.com/yuque/0/2025/png/21449790/1736832965163-2c6859fb-daed-4ac0-a78d-a58e325cb3f1.png" alt="Redis数据结构" class="w-full max-w-xs rounded-lg shadow-2xl transform rotate-3 hover:rotate-0 transition-transform duration-300">
                </div>
            </div>
        </div>
    </section>

    <!-- Navigation -->
    <nav class="bg-white shadow-sm sticky top-0 z-50">
        <div class="container mx-auto px-6 py-4">
            <div class="flex justify-center space-x-8">
                <a href="#basic-types" class="nav-link text-gray-700 hover:text-indigo-600">基本数据类型</a>
                <a href="#advanced-types" class="nav-link text-gray-700 hover:text-indigo-600">高级数据类型</a>
                <a href="#memory-management" class="nav-link text-gray-700 hover:text-indigo-600">内存管理</a>
                <a href="#performance" class="nav-link text-gray-700 hover:text-indigo-600">性能优化</a>
                <a href="#scalability" class="nav-link text-gray-700 hover:text-indigo-600">扩展性</a>
            </div>
        </div>
    </nav>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12">
        <div class="flex flex-col lg:flex-row gap-12">
            <!-- Main Content Area -->
            <div class="w-full lg:w-2/3">
                <!-- Basic Data Types Section -->
                <section id="basic-types" class="mb-20">
                    <div class="flex items-center mb-8">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-layer-group text-indigo-600 text-xl"></i>
                        </div>
                        <h2 class="text-3xl font-bold text-gray-800">Redis 基本数据类型</h2>
                    </div>
                    
                    <p class="text-gray-700 mb-8">Redis 提供了几种常见且高效的数据类型，这些数据类型是其高性能和灵活性的基础。它们不仅支持常见的键值存储功能，还提供了丰富的操作，适用于不同的应用场景。</p>
                    
                    <div class="grid md:grid-cols-2 gap-6 mb-12">
                        <!-- String -->
                        <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <span class="type-tag bg-indigo-100 text-indigo-800 mr-3">String</span>
                                    <i class="fas fa-quote-right text-indigo-500"></i>
                                </div>
                                <h3 class="text-xl font-semibold mb-3">字符串（String）</h3>
                                <p class="text-gray-600 mb-4">Redis 中最基本的数据类型，可以存储任何形式的数据，如文本、数字、二进制数据等。</p>
                                <div class="code-block mb-4">
                                    <p>SET key value</p>
                                    <p>GET key</p>
                                    <p>INCR key</p>
                                    <p>APPEND key value</p>
                                </div>
                                <p class="text-sm text-gray-500"><i class="fas fa-lightbulb mr-2 text-yellow-500"></i>应用场景：用户session信息、计数器等</p>
                            </div>
                        </div>
                        
                        <!-- Hash -->
                        <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <span class="type-tag bg-purple-100 text-purple-800 mr-3">Hash</span>
                                    <i class="fas fa-braille text-purple-500"></i>
                                </div>
                                <h3 class="text-xl font-semibold mb-3">哈希（Hash）</h3>
                                <p class="text-gray-600 mb-4">键值对集合，可以用来存储对象的数据，适合存储具有多个属性的对象。</p>
                                <div class="code-block mb-4">
                                    <p>HSET key field value</p>
                                    <p>HGET key field</p>
                                    <p>HGETALL key</p>
                                    <p>HDEL key field</p>
                                </div>
                                <p class="text-sm text-gray-500"><i class="fas fa-lightbulb mr-2 text-yellow-500"></i>应用场景：用户信息、产品详情等</p>
                            </div>
                        </div>
                        
                        <!-- List -->
                        <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <span class="type-tag bg-blue-100 text-blue-800 mr-3">List</span>
                                    <i class="fas fa-list-ol text-blue-500"></i>
                                </div>
                                <h3 class="text-xl font-semibold mb-3">列表（List）</h3>
                                <p class="text-gray-600 mb-4">有序的数据结构，可以存储多个元素，支持从两端插入和删除元素。</p>
                                <div class="code-block mb-4">
                                    <p>LPUSH key value</p>
                                    <p>RPUSH key value</p>
                                    <p>LPOP key</p>
                                    <p>LRANGE key start stop</p>
                                </div>
                                <p class="text-sm text-gray-500"><i class="fas fa-lightbulb mr-2 text-yellow-500"></i>应用场景：消息队列、任务队列等</p>
                            </div>
                        </div>
                        
                        <!-- Set -->
                        <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <span class="type-tag bg-green-100 text-green-800 mr-3">Set</span>
                                    <i class="fas fa-project-diagram text-green-500"></i>
                                </div>
                                <h3 class="text-xl font-semibold mb-3">集合（Set）</h3>
                                <p class="text-gray-600 mb-4">无序且不允许重复元素的集合，支持各种集合操作。</p>
                                <div class="code-block mb-4">
                                    <p>SADD key member</p>
                                    <p>SREM key member</p>
                                    <p>SMEMBERS key</p>
                                    <p>SINTER key1 key2</p>
                                </div>
                                <p class="text-sm text-gray-500"><i class="fas fa-lightbulb mr-2 text-yellow-500"></i>应用场景：去重、标签系统等</p>
                            </div>
                        </div>
                        
                        <!-- Sorted Set -->
                        <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover col-span-1 md:col-span-2">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <span class="type-tag bg-yellow-100 text-yellow-800 mr-3">Sorted Set</span>
                                    <i class="fas fa-sort-amount-up text-yellow-500"></i>
                                </div>
                                <h3 class="text-xl font-semibold mb-3">有序集合（Sorted Set）</h3>
                                <p class="text-gray-600 mb-4">类似于集合，但每个元素都会关联一个分数，根据分数对元素进行排序。</p>
                                <div class="code-block mb-4">
                                    <p>ZADD key score member</p>
                                    <p>ZRANGE key start stop</p>
                                    <p>ZREVRANGE key start stop</p>
                                    <p>ZREM key member</p>
                                </div>
                                <p class="text-sm text-gray-500"><i class="fas fa-lightbulb mr-2 text-yellow-500"></i>应用场景：排行榜、优先级队列等</p>
                            </div>
                        </div>
                    </div>
                    
                    <div class="data-structure-diagram mb-8">
                        <div class="mermaid">
                            graph LR
                            A[Redis数据结构] --> B[String]
                            A --> C[Hash]
                            A --> D[List]
                            A --> E[Set]
                            A --> F[Sorted Set]
                            
                            B --> G[文本/数字/二进制]
                            C --> H[字段-值映射]
                            D --> I[有序元素集合]
                            E --> J[无序唯一元素]
                            F --> K[带分值的唯一元素]
                            
                            style A fill:#f0f9ff,stroke:#2563eb
                            style B fill:#e0e7ff,stroke:#4f46e5
                            style C fill:#ede9fe,stroke:#8b5cf6
                            style D fill:#e0e7ff,stroke:#4f46e5
                            style E fill:#ecfdf5,stroke:#10b981
                            style F fill:#fef3c7,stroke:#f59e0b
                        </div>
                    </div>
                    
                    <img src="https://cdn.nlark.com/yuque/0/2025/png/21449790/1736832997366-4eeb5864-d3b7-480a-af43-91490876964e.png" alt="Redis数据类型比较" class="w-full rounded-lg shadow-md mb-8">
                </section>
                
                <!-- Advanced Data Types Section -->
                <section id="advanced-types" class="mb-20">
                    <div class="flex items-center mb-8">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-star text-indigo-600 text-xl"></i>
                        </div>
                        <h2 class="text-3xl font-bold text-gray-800">Redis 高级数据类型</h2>
                    </div>
                    
                    <p class="text-gray-700 mb-8">除了基本数据类型，Redis 还提供了一些高级数据类型，能够满足更复杂的应用需求。这些高级数据类型不仅在内存管理上更加高效，而且为处理大规模数据和特定场景下的优化提供了丰富的功能。</p>
                    
                    <div class="grid md:grid-cols-2 gap-6 mb-12">
                        <!-- Bitmap -->
                        <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <span class="type-tag bg-red-100 text-red-800 mr-3">Bitmap</span>
                                    <i class="fas fa-border-all text-red-500"></i>
                                </div>
                                <h3 class="text-xl font-semibold mb-3">位图（Bitmap）</h3>
                                <p class="text-gray-600 mb-4">以位为单位存储和操作数据的数据结构，可表示大量布尔值（0或1）。</p>
                                <div class="code-block mb-4">
                                    <p>SETBIT key offset value</p>
                                    <p>GETBIT key offset</p>
                                    <p>BITCOUNT key</p>
                                    <p>BITOP operation destkey key</p>
                                </div>
                                <p class="text-sm text-gray-500"><i class="fas fa-lightbulb mr-2 text-yellow-500"></i>应用场景：访问统计、用户活跃度分析</p>
                            </div>
                        </div>
                        
                        <!-- HyperLogLog -->
                        <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <span class="type-tag bg-pink-100 text-pink-800 mr-3">HyperLogLog</span>
                                    <i class="fas fa-infinity text-pink-500"></i>
                                </div>
                                <h3 class="text-xl font-semibold mb-3">HyperLogLog</h3>
                                <p class="text-gray-600 mb-4">用于基数估算的概率性数据结构，能以极小内存消耗统计大量唯一元素。</p>
                                <div class="code-block mb-4">
                                    <p>PFADD key element</p>
                                    <p>PFCOUNT key</p>
                                    <p>PFMERGE destkey sourcekey</p>
                                </div>
                                <p class="text-sm text-gray-500"><i class="fas fa-lightbulb mr-2 text-yellow-500"></i>应用场景：独立访客统计、点击量统计</p>
                            </div>
                        </div>
                        
                        <!-- Geospatial -->
                        <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <span class="type-tag bg-teal-100 text-teal-800 mr-3">Geospatial</span>
                                    <i class="fas fa-map-marker-alt text-teal-500"></i>
                                </div>
                                <h3 class="text-xl font-semibold mb-3">地理空间（Geospatial）</h3>
                                <p class="text-gray-600 mb-4">支持存储、查询和分析基于地理坐标的位置信息。</p>
                                <div class="code-block mb-4">
                                    <p>GEOADD key lon lat member</p>
                                    <p>GEODIST key member1 member2</p>
                                    <p>GEORADIUS key lon lat radius</p>
                                </div>
                                <p class="text-sm text-gray-500"><i class="fas fa-lightbulb mr-2 text-yellow-500"></i>应用场景：位置服务、门店定位</p>
                            </div>
                        </div>
                        
                        <!-- Streams -->
                        <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <span class="type-tag bg-indigo-100 text-indigo-800 mr-3">Streams</span>
                                    <i class="fas fa-stream text-indigo-500"></i>
                                </div>
                                <h3 class="text-xl font-semibold mb-3">流（Streams）</h3>
                                <p class="text-gray-600 mb-4">Redis 5.0引入的新数据类型，支持存储时间序列数据，类似消息队列。</p>
                                <div class="code-block mb-4">
                                    <p>XADD key ID field value</p>
                                    <p>XREAD STREAMS key</p>
                                    <p>XREADGROUP GROUP group consumer</p>
                                </div>
                                <p class="text-sm text-gray-500"><i class="fas fa-lightbulb mr-2 text-yellow-500"></i>应用场景：日志收集、事件处理</p>
                            </div>
                        </div>
                    </div>
                    
                    <img src="https://cdn.nlark.com/yuque/0/2025/png/21449790/1736833054250-f81a4890-e426-47c2-9320-3b52ac02bee5.png" alt="Redis高级数据类型" class="w-full rounded-lg shadow-md mb-8">
                </section>
                
                <!-- Memory Management Section -->
                <section id="memory-management" class="mb-20">
                    <div class="flex items-center mb-8">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-memory text-indigo-600 text-xl"></i>
                        </div>
                        <h2 class="text-3xl font-bold text-gray-800">Redis 内存管理机制</h2>
                    </div>
                    
                    <p class="text-gray-700 mb-8">Redis 是一个高性能的键值数据库，广泛用于缓存和实时数据处理。在实际应用中，Redis 经常面临着大量数据存储的挑战，如何高效地管理内存变得至关重要。</p>
                    
                    <div class="grid md:grid-cols-2 gap-6 mb-12">
                        <!-- Memory Model -->
                        <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <i class="fas fa-microchip text-blue-500 mr-3"></i>
                                    <h3 class="text-xl font-semibold">内存模型</h3>
                                </div>
                                <p class="text-gray-600 mb-4">Redis 的内存管理基于操作系统的内存分配机制，使用内存池减少频繁分配与释放带来的性能开销。</p>
                                <div class="space-y-2">
                                    <div class="flex items-start">
                                        <i class="fas fa-circle text-blue-500 text-xs mt-1 mr-2"></i>
                                        <span><strong>jemalloc</strong>：Redis 默认的内存分配器，具有低碎片、高性能和多线程支持的优点</span>
                                    </div>
                                    <div class="flex items-start">
                                        <i class="fas fa-circle text-blue-500 text-xs mt-1 mr-2"></i>
                                        <span><strong>tcmalloc</strong>：在高并发和大内存需求场景下有更好的性能表现</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!-- Data Structures -->
                        <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <i class="fas fa-sitemap text-purple-500 mr-3"></i>
                                    <h3 class="text-xl font-semibold">内存数据结构</h3>
                                </div>
                                <p class="text-gray-600 mb-4">Redis 根据数据结构的大小和操作频繁度，决定是否使用高效的内存编码来存储数据。</p>
                                <div class="space-y-2">
                                    <div class="flex items-start">
                                        <i class="fas fa-circle text-purple-500 text-xs mt-1 mr-2"></i>
                                        <span><strong>SDS</strong>：简单动态字符串，支持动态增长</span>
                                    </div>
                                    <div class="flex items-start">
                                        <i class="fas fa-circle text-purple-500 text-xs mt-1 mr-2"></i>
                                        <span><strong>ziplist</strong>：小规模数据时使用压缩格式</span>
                                    </div>
                                    <div class="flex items-start">
                                        <i class="fas fa-circle text-purple-500 text-xs mt-1 mr-2"></i>
                                        <span><strong>intset/skiplist</strong>：根据集合大小自动选择</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!-- Memory Reclaim -->
                        <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <i class="fas fa-recycle text-green-500 mr-3"></i>
                                    <h3 class="text-xl font-semibold">内存回收</h3>
                                </div>
                                <p class="text-gray-600 mb-4">Redis 主要通过键的过期机制和两种删除策略进行内存回收。</p>
                                <div class="space-y-2">
                                    <div class="flex items-start">
                                        <i class="fas fa-circle text-green-500 text-xs mt-1 mr-2"></i>
                                        <span><strong>键过期机制</strong>：为键设置TTL，超时后自动删除</span>
                                    </div>
                                    <div class="flex items-start">
                                        <i class="fas fa-circle text-green-500 text-xs mt-1 mr-2"></i>
                                        <span><strong>惰性删除</strong>：访问时检查并删除过期键</span>
                                    </div>
                                    <div class="flex items-start">
                                        <i class="fas fa-circle text-green-500 text-xs mt-1 mr-2"></i>
                                        <span><strong>定期删除</strong>：随机扫描部分键删除过期键</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!-- Eviction Policy -->
                        <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <i class="fas fa-filter text-yellow-500 mr-3"></i>
                                    <h3 class="text-xl font-semibold">淘汰策略</h3>
                                </div>
                                <p class="text-gray-600 mb-4">Redis 提供了多种内存淘汰策略，在内存不足时自动删除数据。</p>
                                <div class="space-y-2">
                                    <div class="flex items-start">
                                        <i class="fas fa-circle text-yellow-500 text-xs mt-1 mr-2"></i>
                                        <span><strong>noeviction</strong>：不删除，返回错误</span>
                                    </div>
                                    <div class="flex items-start">
                                        <i class="fas fa-circle text-yellow-500 text-xs mt-1 mr-2"></i>
                                        <span><strong>allkeys-lru</strong>：删除最近最少使用的键</span>
                                    </div>
                                    <div class="flex items-start">
                                        <i class="fas fa-circle text-yellow-500 text-xs mt-1 mr-2"></i>
                                        <span><strong>volatile-ttl</strong>：删除即将过期的键</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="data-structure-diagram mb-8">
                        <div class="mermaid">
                            flowchart TD
                            A[Redis内存管理] --> B[内存分配]
                            A --> C[数据结构优化]
                            A --> D[内存回收]
                            A --> E[淘汰策略]
                            
                            B --> F[jemalloc/tcmalloc]
                            C --> G[ziplist/quicklist/intset]
                            D --> H[惰性删除]
                            D --> I[定期删除]
                            E --> J[LRU/LFU/TTL]
                            
                            style A fill:#f0f9ff,stroke:#2563eb
                            style B fill:#e0f2fe,stroke:#38bdf8
                            style C fill:#ecfdf5,stroke:#10b981
                            style D fill:#fef3c7,stroke:#f59e0b
                            style E fill:#fee2e2,stroke:#ef4444
                        </div>
                    </div>
                    
                    <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
                        <div class="p-6">
                            <h3 class="text-xl font-semibold mb-4 flex items-center">
                                <i class="fas fa-chart-line text-indigo-500 mr-3"></i>
                                内存监控与调优
                            </h3>
                            <p class="text-gray-600 mb-4">Redis 提供了多种命令来帮助开发者监控内存使用情况：</p>
                            <div class="grid md:grid-cols-3 gap-4">
                                <div class="code-block">
                                    <p class="font-semibold">INFO memory</p>
                                    <p>获取内存详细信息，包括总使用量、碎片率等</p>
                                </div>
                                <div class="code-block">
                                    <p class="font-semibold">MEMORY USAGE key</p>
                                    <p>查看某个键占用的内存</p>
                                </div>
                                <div class="code-block">
                                    <p class="font-semibold">MEMORY STATS</p>
                                    <p>获取内存统计信息</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>
                
                <!-- Performance Optimization Section -->
                <section id="performance" class="mb-20">
                    <div class="flex items-center mb-8">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-tachometer-alt text-indigo-600 text-xl"></i>
                        </div>
                        <h2 class="text-3xl font-bold text-gray-800">Redis 性能优化</h2>
                    </div>
                    
                    <p class="text-gray-700 mb-8">Redis 是一个高性能的内存数据存储系统，通过合理优化可以进一步提升其性能表现。</p>
                    
                    <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
                        <div class="p-6">
                            <div class="grid md:grid-cols-2 gap-6">
                                <!-- Memory Optimization -->
                                <div>
                                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                                        <i class="fas fa-memory text-blue-500 mr-3"></i>
                                        内存优化
                                    </h3>
                                    <ul class="space-y-3">
                                        <li class="flex items-start">
                                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                            <span>选择合适的数据类型存储数据</span>
                                        </li>
                                        <li class="flex items-start">
                                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                            <span>利用内存编码优化（ziplist, intset等）</span>
                                        </li>
                                        <li class="flex items-start">
                                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                            <span>定期清理过期键和无用数据</span>
                                        </li>
                                    </ul>
                                </div>
                                
                                <!-- Persistence Optimization -->
                                <div>
                                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                                        <i class="fas fa-save text-purple-500 mr-3"></i>
                                        持久化优化
                                    </h3>
                                    <ul class="space-y-3">
                                        <li class="flex items-start">
                                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                            <span>合理设置RDB保存频率</span>
                                        </li>
                                        <li class="flex items-start">
                                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                            <span>使用AOF重写优化文件大小</span>
                                        </li>
                                        <li class="flex items-start">
                                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                            <span>考虑混合持久化（RDB+AOF）</span>
                                        </li>
                                    </ul>
                                </div>
                                
                                <!-- Network Optimization -->
                                <div>
                                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                                        <i class="fas fa-network-wired text-green-500 mr-3"></i>
                                        网络优化
                                    </h3>
                                    <ul class="space-y-3">
                                        <li class="flex items-start">
                                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                            <span>使用管道（Pipelining）减少网络往返</span>
                                        </li>
                                        <li class="flex items-start">
                                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                            <span>考虑Redis Cluster分片</span>
                                        </li>
                                        <li class="flex items-start">
                                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                            <span>尽量使用批量操作（MSET/MGET）</span>
                                        </li>
                                    </ul>
                                </div>
                                
                                <!-- Query Optimization -->
                                <div>
                                    <h3 class="text-xl font-semibold mb-4 flex items-center">
                                        <i class="fas fa-search text-yellow-500 mr-3"></i>
                                        查询优化
                                    </h3>
                                    <ul class="space-y-3">
                                        <li class="flex items-start">
                                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                            <span>避免使用KEYS命令，改用SCAN</span>
                                        </li>
                                        <li class="flex items-start">
                                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                            <span>为常用查询构建索引</span>
                                        </li>
                                        <li class="flex items-start">
                                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                            <span>合理使用Lua脚本减少网络IO</span>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="data-structure-diagram mb-8">
                        <div class="mermaid">
                            pie showData
                            title Redis性能优化关键点
                            "内存优化" : 35
                            "持久化优化" : 25
                            "网络优化" : 20
                            "查询优化" : 20
                        </div>
                    </div>
                </section>
                
                <!-- Scalability Section -->
                <section id="scalability" class="mb-20">
                    <div class="flex items-center mb-8">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-expand text-indigo-600 text-xl"></i>
                        </div>
                        <h2 class="text-3xl font-bold text-gray-800">Redis 扩展性</h2>
                    </div>
                    
                    <p class="text-gray-700 mb-8">Redis 的扩展性是其能广泛应用于大规模分布式系统的核心优势之一。通过各种扩展机制，Redis 可以支持大规模的数据存储和高并发的请求处理。</p>
                    
                    <div class="grid md:grid-cols-2 gap-6 mb-12">
                        <!-- Vertical Scaling -->
                        <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <i class="fas fa-arrow-up text-blue-500 mr-3"></i>
                                    <h3 class="text-xl font-semibold">垂直扩展（Scale Up）</h3>
                                </div>
                                <p class="text-gray-600 mb-4">通过增加硬件资源（如CPU、内存等）来扩展Redis的容量和性能。</p>
                                <div class="space-y-2">
                                    <div class="flex items-start">
                                        <i class="fas fa-server text-blue-500 mr-2 mt-1"></i>
                                        <span>增加单机内存容量</span>
                                    </div>
                                    <div class="flex items-start">
                                        <i class="fas fa-microchip text-blue-500 mr-2 mt-1"></i>
                                        <span>升级CPU性能</span>
                                    </div>
                                    <div class="flex items-start">
                                        <i class="fas fa-hdd text-blue-500 mr-2 mt-1"></i>
                                        <span>使用更快的存储设备</span>
                                    </div>
                                </div>
                                <div class="mt-4 p-3 bg-blue-50 rounded-lg">
                                    <p class="text-sm text-blue-800"><i class="fas fa-info-circle mr-2"></i>适用于中小规模Redis实例，简单但扩展有限</p>
                                </div>
                            </div>
                        </div>
                        
                        <!-- Horizontal Scaling -->
                        <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                            <div class="p-6">
                                <div class="flex items-center mb-4">
                                    <i class="fas fa-arrows-alt-h text-purple-500 mr-3"></i>
                                    <h3 class="text-xl font-semibold">水平扩展（Scale Out）</h3>
                                </div>
                                <p class="text-gray-600 mb-4">通过分布式技术，将Redis数据分布到多个节点上，实现负载均衡和高可用性。</p>
                                <div class="space-y-2">
                                    <div class="flex items-start">
                                        <i class="fas fa-project-diagram text-purple-500 mr-2 mt-1"></i>
                                        <span><strong>Redis Cluster</strong>：内置分片功能，自动分布数据</span>
                                    </div>
                                    <div class="flex items-start">
                                        <i class="fas fa-shield-alt text-purple-500 mr-2 mt-1"></i>
                                        <span><strong>Sentinel</strong>：监控主节点，自动故障转移</span>
                                    </div>
                                    <div class="flex items-start">
                                        <i class="fas fa-sitemap text-purple-500 mr-2 mt-1"></i>
                                        <span><strong>Proxy</strong>：如Twemproxy、Codis等</span>
                                    </div>
                                </div>
                                <div class="mt-4 p-3 bg-purple-50 rounded-lg">
                                    <p class="text-sm text-purple-800"><i class="fas fa-info-circle mr-2"></i>适用于大规模分布式环境，扩展性强</p>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
                        <div class="p-6">
                            <h3 class="text-xl font-semibold mb-4 flex items-center">
                                <i class="fas fa-share-alt text-indigo-500 mr-3"></i>
                                数据复制与高可用性
                            </h3>
                            <div class="grid md:grid-cols-2 gap-6">
                                <div>
                                    <h4 class="font-semibold mb-2 text-gray-700 flex items-center">
                                        <i class="fas fa-copy text-blue-500 mr-2"></i>
                                        主从复制
                                    </h4>
                                    <p class="text-gray-600">Redis 支持主从复制，主节点处理写请求，从节点同步主节点数据，提供读请求的分担。</p>
                                    <div class="code-block mt-3">
                                        <p># 配置从节点</p>
                                        <p>replicaof &lt;masterip&gt; &lt;masterport&gt;</p>
                                    </div>
                                </div>
                                <div>
                                    <h4 class="font-semibold mb-2 text-gray-700 flex items-center">
                                        <i class="fas fa-exchange-alt text-green-500 mr-2"></i>
                                        故障转移
                                    </h4>
                                    <p class="text-gray-600">Redis Sentinel 监控主节点状态，在主节点故障时自动将从节点提升为新主节点。</p>
                                    <div class="code-block mt-3">
                                        <p># Sentinel 配置示例</p>
                                        <p>sentinel monitor mymaster 127.0.0.1 6379 2</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="data-structure-diagram">
                        <div class="mermaid">
                            graph TD
                            A[Redis扩展方案] --> B[垂直扩展]
                            A --> C[水平扩展]
                            
                            B --> D[增加内存]
                            B --> E[升级CPU]
                            B --> F[优化存储]
                            
                            C --> G[Redis Cluster]
                            C --> H[Sentinel]
                            C --> I[Proxy]
                            
                            G --> J[自动分片]
                            G --> K[数据迁移]
                            G --> L[高可用]
                            
                            H --> M[监控]
                            H --> N[自动故障转移]
                            H --> O[配置提供者]
                            
                            style A fill:#f0f9ff,stroke:#2563eb
                            style B fill:#e0e7ff,stroke:#4f46e5
                            style C fill:#ede9fe,stroke:#8b5cf6
                        </div>
                    </div>
                </section>
            </div>
            
            <!-- Sidebar -->
            <div class="w-full lg:w-1/3">
                <div class="sticky top-20">
                    <!-- Table of Contents -->
                    <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
                        <div class="p-6">
                            <h3 class="text-xl font-semibold mb-4 flex items-center">
                                <i class="fas fa-list-ul text-indigo-500 mr-3"></i>
                                内容目录
                            </h3>
                            <ul class="space-y-2">
                                <li>
                                    <a href="#basic-types" class="flex items-center text-gray-700 hover:text-indigo-600">
                                        <i class="fas fa-circle text-xs text-indigo-500 mr-3"></i>
                                        <span>基本数据类型</span>
                                    </a>
                                </li>
                                <li class="ml-4">
                                    <a href="#basic-types" class="flex items-center text-gray-500 hover:text-indigo-600 text-sm">
                                        <i class="fas fa-chevron-right text-xs text-gray-400 mr-2"></i>
                                        <span>字符串（String）</span>
                                    </a>
                                </li>
                                <li class="ml-4">
                                    <a href="#basic-types" class="flex items-center text-gray-500 hover:text-indigo-600 text-sm">
                                        <i class="fas fa-chevron-right text-xs text-gray-400 mr-2"></i>
                                        <span>哈希（Hash）</span>
                                    </a>
                                </li>
                                <li class="ml-4">
                                    <a href="#basic-types" class="flex items-center text-gray-500 hover:text-indigo-600 text-sm">
                                        <i class="fas fa-chevron-right text-xs text-gray-400 mr-2"></i>
                                        <span>列表（List）</span>
                                    </a>
                                </li>
                                <li class="ml-4">
                                    <a href="#basic-types" class="flex items-center text-gray-500 hover:text-indigo-600 text-sm">
                                        <i class="fas fa-chevron-right text-xs text-gray-400 mr-2"></i>
                                        <span>集合（Set）</span>
                                    </a>
                                </li>
                                <li class="ml-4">
                                    <a href="#basic-types" class="flex items-center text-gray-500 hover:text-indigo-600 text-sm">
                                        <i class="fas fa-chevron-right text-xs text-gray-400 mr-2"></i>
                                        <span>有序集合（Sorted Set）</span>
                                    </a>
                                </li>
                                <li>
                                    <a href="#advanced-types" class="flex items-center text-gray-700 hover:text-indigo-600">
                                        <i class="fas fa-circle text-xs text-indigo-500 mr-3"></i>
                                        <span>高级数据类型</span>
                                    </a>
                                </li>
                                <li class="ml-4">
                                    <a href="#advanced-types" class="flex items-center text-gray-500 hover:text-indigo-600 text-sm">
                                        <i class="fas fa-chevron-right text-xs text-gray-400 mr-2"></i>
                                        <span>位图（Bitmap）</span>
                                    </a>
                                </li>
                                <li class="ml-4">
                                    <a href="#advanced-types" class="flex items-center text-gray-500 hover:text-indigo-600 text-sm">
                                        <i class="fas fa-chevron-right text-xs text-gray-400 mr-2"></i>
                                        <span>HyperLogLog</span>
                                    </a>
                                </li>
                                <li class="ml-4">
                                    <a href="#advanced-types" class="flex items-center text-gray-500 hover:text-indigo-600 text-sm">
                                        <i class="fas fa-chevron-right text-xs text-gray-400 mr-2"></i>
                                        <span>地理空间（Geospatial）</span>
                                    </a>
                                </li>
                                <li class="ml-4">
                                    <a href="#advanced-types" class="flex items-center text-gray-500 hover:text-indigo-600 text-sm">
                                        <i class="fas fa-chevron-right text-xs text-gray-400 mr-2"></i>
                                        <span>流（Streams）</span>
                                    </a>
                                </li>
                                <li>
                                    <a href="#memory-management" class="flex items-center text-gray-700 hover:text-indigo-600">
                                        <i class="fas fa-circle text-xs text-indigo-500 mr-3"></i>
                                        <span>内存管理机制</span>
                                    </a>
                                </li>
                                <li>
                                    <a href="#performance" class="flex items-center text-gray-700 hover:text-indigo-600">
                                        <i class="fas fa-circle text-xs text-indigo-500 mr-3"></i>
                                        <span>性能优化</span>
                                    </a>
                                </li>
                                <li>
                                    <a href="#scalability" class="flex items-center text-gray-700 hover:text-indigo-600">
                                        <i class="fas fa-circle text-xs text-indigo-500 mr-3"></i>
                                        <span>扩展性</span>
                                    </a>
                                </li>
                            </ul>
                        </div>
                    </div>
                    
                    <!-- Key Points -->
                    <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
                        <div class="p-6">
                            <h3 class="text-xl font-semibold mb-4 flex items-center">
                                <i class="fas fa-key text-indigo-500 mr-3"></i>
                                核心要点
                            </h3>
                            <div class="space-y-4">
                                <div class="flex items-start">
                                    <div class="flex-shrink-0 h-10 w-10 bg-indigo-100 rounded-full flex items-center justify-center mr-3">
                                        <i class="fas fa-bolt text-indigo-600"></i>
                                    </div>
                                    <div>
                                        <h4 class="font-semibold text-gray-800">高效内存利用</h4>
                                        <p class="text-gray-600 text-sm">Redis 通过多种编码方式优化内存使用，如 ziplist、intset 等，大幅减少内存消耗。</p>
                                    </div>
                                </div>
                                <div class="flex items-start">
                                    <div class="flex-shrink-0 h-10 w-10 bg-purple-100 rounded-full flex items-center justify-center mr-3">
                                        <i class="fas fa-shield-alt text-purple-600"></i>
                                    </div>
                                    <div>
                                        <h4 class="font-semibold text-gray-800">数据持久化</h4>
                                        <p class="text-gray-600 text-sm">RDB 和 AOF 两种持久化机制，可根据业务需求选择或混合使用。</p>
                                    </div>
                                </div>
                                <div class="flex items-start">
                                    <div class="flex-shrink-0 h-10 w-10 bg-blue-100 rounded-full flex items-center justify-center mr-3">
                                        <i class="fas fa-expand-arrows-alt text-blue-600"></i>
                                    </div>
                                    <div>
                                        <h4 class="font-semibold text-gray-800">水平扩展</h4>
                                        <p class="text-gray-600 text-sm">Redis Cluster 支持自动分片，Sentinel 提供高可用，满足大规模部署需求。</p>
                                    </div>
                                </div>
                                <div class="flex items-start">
                                    <div class="flex-shrink-0 h-10 w-10 bg-green-100 rounded-full flex items-center justify-center mr-3">
                                        <i class="fas fa-tachometer-alt text-green-600"></i>
                                    </div>
                                    <div>
                                        <h4 class="font-semibold text-gray-800">高性能</h4>
                                        <p class="text-gray-600 text-sm">单线程模型、内存操作、高效数据结构共同造就 Redis 的卓越性能。</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Redis Command Cheat Sheet -->
                    <div class="bg-white rounded-xl shadow-md overflow-hidden">
                        <div class="p-6">
                            <h3 class="text-xl font-semibold mb-4 flex items-center">
                                <i class="fas fa-terminal text-indigo-500 mr-3"></i>
                                Redis 命令速查
                            </h3>
                            <div class="space-y-3">
                                <div class="code-block p-3">
                                    <p class="font-semibold">INFO memory</p>
                                    <p class="text-gray-600 text-sm">查看内存使用情况</p>
                                </div>
                                <div class="code-block p-3">
                                    <p class="font-semibold">CONFIG GET maxmemory</p>
                                    <p class="text-gray-600 text-sm">获取内存限制配置</p>
                                </div>
                                <div class="code-block p-3">
                                    <p class="font-semibold">MEMORY USAGE key</p>
                                    <p class="text-gray-600 text-sm">查看键的内存占用</p>
                                </div>
                                <div class="code-block p-3">
                                    <p class="font-semibold">CLIENT LIST</p>
                                    <p class="text-gray-600 text-sm">查看客户端连接</p>
                                </div>
                                <div class="code-block p-3">
                                    <p class="font-semibold">SLOWLOG GET</p>
                                    <p class="text-gray-600 text-sm">查看慢查询日志</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="container mx-auto px-6">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-semibold text-white mb-2">技术小馆</h3>
                    <a href="http://www.yuque.com/jtostring" class="text-gray-400 hover:text-white transition-colors duration-300">
                        <i class="fas fa-link mr-2"></i>http://www.yuque.com/jtostring
                    </a>
                </div>
                <div class="flex space-x-6">
                    <a href="#" class="text-gray-400 hover:text-white transition-colors duration-300">
                        <i class="fab fa-github text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white transition-colors duration-300">
                        <i class="fab fa-twitter text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white transition-colors duration-300">
                        <i class="fab fa-weixin text-xl"></i>
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-sm text-gray-500 text-center">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // Smooth scrolling for anchor links
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
        
        // Highlight active navigation item
        const sections = document.querySelectorAll('section');
        const navLinks = document.querySelectorAll('.nav-link');
        
        window.addEventListener('scroll', () => {
            let current = '';
            
            sections.forEach(section => {
                const sectionTop = section.offsetTop;
                const sectionHeight = section.clientHeight;
                
                if (pageYOffset >= sectionTop - 100) {
                    current = section.getAttribute('id');
                }
            });
            
            navLinks.forEach(link => {
                link.classList.remove('active-nav');
                if (link.getAttribute('href') === `#${current}`) {
                    link.classList.add('active-nav');
                }
            });
        });
    </script>
</body>
</html>